
#include "findur.h"
#include "ui_findur.h"
#include "interface_control.h"
#include "client_connet.h"

#include <qpushbutton.h>
#include <QLabel>

Findur::Findur(QWidget *parent, QString id,QString name) :
    QWidget(parent),
    ui(new Ui::Findur)
{
    ui->setupUi(this);
    this->resize(790,100);
    //初始化成员
    ue.ID = id;
    ue.name = name;

    QPushButton *touxiang = new QPushButton(this);
    touxiang->setGeometry(0,0,200,100);
    touxiang->setText("头像");

    QLabel *find_l = new QLabel(this);
    find_l->setGeometry(300,0,200,100);
    find_l->setText(ue.name);

    QPushButton *talk = new QPushButton(this);
    talk->setGeometry(600,0,100,100);
    talk->setText("添加好友");
    connect(talk,&QPushButton::clicked,[&]()
    {
       friends f;
       f.name = ue.name;
       f.friendloginid = ue.ID;
       f.FriendGroups = 0;//因为无改属性，默认为0

       //传入好友列表
        Client_connet::Get_Connet()->setfrarr(f);

        //通过指针为好友界面添加一个对象
        Interface_Control::getControlptr()->getm_s()->AddFriend(f.friendloginid,f.name,f.FriendGroups);

        QJsonObject js;
        js.insert("cmd",3);
        js.insert("loginid",Client_connet::Get_Connet()->me.ID);
        js.insert("friendid",ue.ID);
        js.insert("ownname",Client_connet::Get_Connet()->me.name);
        js.insert("friname",ue.name);

        Client_connet::Get_Connet()->set_obj(js);
        Client_connet::Get_Connet()->SendServer();

        //添加后界面刷新（通过关闭开启的方式）
        Interface_Control::getControlptr()->showm_fr();
        Interface_Control::getControlptr()->getm_fr()->flushedFre();


    });
}

Findur::~Findur()
{
    delete ui;
}
